// pages/detailed/detailed.js
const FundCharts = require('../../FundCharts.min.js');
const BarChart = FundCharts.bar
Page({
  /**
   * 页面的初始数据
   */
  data: {
    date: '2016-09-01',
    pro:[
      {
        image:'/img/a.png',
        zhichu:'日常支出',
        qian:'20',
        b:'15',
        zongjine:'3000,00'
      },{
        image:'/img/y.png',
        zhichu:'其他支出',
        qian:'10',
        b:'55',
        zongjine:'1000,00'
      },{
        image:'/img/c.png',
        zhichu:'现金支出',
        qian:'70',
        b:'80',
        zongjine:'7000,00'
      },
    ],
    send:[
      {
        image:'/img/a.png',
        zhichu:'日常收入',
        qian:'40',
        b:'20',
        zongjine:'4000,00'
      },{
        image:'/img/y.png',
        zhichu:'其他收入',
        qian:'20',
        b:'55',
        zongjine:'2000,00'
      },{
        image:'/img/c.png',
        zhichu:'现金收入',
        qian:'40',
        b:'80',
        zongjine:'4000,00'
      },
    ],
    items:[
      { 
        name: '支出',
       checked: true,
       vv:0
      },
      { 
        name: '收入',
       checked: false,
       vv:1
      }
    ],
    item:[
      {
        sed:'',
      },{
        sed:'',
      }
    ],
    aaa:'',
    statusList:[]
  },
  changeSex:function(e){//单选
    console.log(e);
    var than=this
    than.setData({
      aaa:e.currentTarget.dataset.id
    })
    
    console.log(this.data.aaa);
    
  },
  bindDateChange: function(e) {//日期选择
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  onLoad: function (options) {
    var that=this
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=expenditure',
      method:'POST',
      data:{
        openid:wx.getStorageSync('open')
      },
      success(res){
        that.RenderbarChart(res.data)
        // console.log(res.data);
      }
    })
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=income',
      method:'POST',
      data:{
        openid:wx.getStorageSync('open')
      },
      success(res){
        that.Renderbar(res.data)
        // console.log(res.data);
      }
    })
  },
  RenderbarChart(statusList){
    // delete statusList[0].id;
    // delete statusList[0].openid;
    // console.log(statusList);
    // return false;
    var bar = new BarChart({
      id: 'chart',
      width: 375,    // 设置宽度
      height: 212,    // 设置高度
      xaxis: ['200', '400', '600','800','1000'],
      // datas: [[7,5,2,5,2,6,7]],	// 或设置为data: [1, 2, 3],
      data:statusList,// 或设置为data: [1, 2, 3],
      noDash:true,//无虚线网格
      barMargin:20,//柱形图之间间隔，
      chartLeft:1,//距左边距离
      chartRight:10,//距右边距离
      chartTop:0,//距顶部距离
      colors:['#ffffff'],//线条颜色
      range:{min: 0, max: 700},
      grid:{
        showGrid:false,
        color:'red',
      }
    });
    bar.init();
    // ctx.draw(true)
  },
  Renderbar(statusList){
    console.log(statusList);
    var bar = new BarChart({
      id: 'cent',
      width: 375,    // 设置宽度
      height: 212,    // 设置高度
      xaxis: ['200', '400', '600','800','1000'],
      // datas: [[7,5,2,5,2,6,7]],	// 或设置为data: [1, 2, 3],
      data:statusList,// 或设置为data: [1, 2, 3],
      noDash:true,//无虚线网格
      barMargin:20,//柱形图之间间隔，
      chartLeft:1,//距左边距离
      chartRight:10,//距右边距离
      chartTop:0,//距顶部距离
      colors:['#ffffff'],//线条颜色
      range:{min: 0, max: 700},
      grid:{
        showGrid:false,
        color:'red',
      }
    });
    bar.init();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})